package MeteoCal.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @authors Guttadoro, Iommazzo, Saullo
 */
@Entity
@Table(name = "comment")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Comment.findAll", query = "SELECT c FROM Comment c"),
    @NamedQuery(name = "Comment.findByIdComment", query = "SELECT c FROM Comment c WHERE c.idComment = :idComment"),
    @NamedQuery(name = "Comment.findByText", query = "SELECT c FROM Comment c WHERE c.text = :text"),
    @NamedQuery(name = "Comment.findByDate", query = "SELECT c FROM Comment c WHERE c.date = :date"),
    @NamedQuery(name = "Comment.findByHour", query = "SELECT c FROM Comment c WHERE c.hour = :hour")})
public class Comment implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "idComment")
    private Integer idComment;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 300)
    @Column(name = "Text")
    private String text;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Date")
    @Temporal(TemporalType.DATE)
    private Date date;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Hour")
    @Temporal(TemporalType.TIME)
    private Date hour;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "comment")
    private Collection<Commentwritten> commentwrittenCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "comment")
    private Collection<Warningcomment> warningcommentCollection;
    @JoinColumn(name = "idEvent", referencedColumnName = "idEvent")
    @ManyToOne(optional = false)
    private Event idEvent;
    @JoinColumn(name = "idAuthor", referencedColumnName = "Email")
    @ManyToOne(optional = false)
    private User idAuthor;

    public Comment() {
    }

    public Comment(Integer idComment) {
        this.idComment = idComment;
    }

    public Comment(Integer idComment, String text, Date date, Date hour) {
        this.idComment = idComment;
        this.text = text;
        this.date = date;
        this.hour = hour;
    }

    public Integer getIdComment() {
        return idComment;
    }

    public void setIdComment(Integer idComment) {
        this.idComment = idComment;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Date getHour() {
        return hour;
    }

    public void setHour(Date hour) {
        this.hour = hour;
    }

    @XmlTransient
    public Collection<Commentwritten> getCommentwrittenCollection() {
        return commentwrittenCollection;
    }

    public void setCommentwrittenCollection(Collection<Commentwritten> commentwrittenCollection) {
        this.commentwrittenCollection = commentwrittenCollection;
    }

    @XmlTransient
    public Collection<Warningcomment> getWarningcommentCollection() {
        return warningcommentCollection;
    }

    public void setWarningcommentCollection(Collection<Warningcomment> warningcommentCollection) {
        this.warningcommentCollection = warningcommentCollection;
    }

    public Event getIdEvent() {
        return idEvent;
    }

    public void setIdEvent(Event idEvent) {
        this.idEvent = idEvent;
    }

    public User getIdAuthor() {
        return idAuthor;
    }

    public void setIdAuthor(User idAuthor) {
        this.idAuthor = idAuthor;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idComment != null ? idComment.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Comment)) {
            return false;
        }
        Comment other = (Comment) object;
        if ((this.idComment == null && other.idComment != null) || (this.idComment != null && !this.idComment.equals(other.idComment))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MeteoCal.entity.Comment[ idComment=" + idComment + " ]";
    }
    
}
